package com.libweb.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.libweb.model.dao.BookDao;

@WebServlet("/book/delete.action")
public class BookDeleteServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		//1. 요청 데이터 읽기 (글번호)
		String bookNo = req.getParameter("bookno");
		if (bookNo == null || bookNo.length() == 0) {
			resp.sendRedirect("list.action");
			return;
		}
		
		//2. 데이터 처리 (db에서 데이터 변경)
		BookDao dao = new BookDao();
		dao.deleteBook(Integer.parseInt(bookNo));
		
		//3. 목록으로 이동 		
		resp.sendRedirect("list.action");	
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		req.setCharacterEncoding("utf-8");
		doGet(req, resp);
	}
	
}




